package com.bupt.kgplatform.controller.jinrui;


import com.bupt.kgplatform.config.MinioProperties;
import com.bupt.kgplatform.entity.pojo.MinioPojo;
import com.bupt.kgplatform.entity.pojo.Result;
import com.bupt.kgplatform.service.MinioService;
import io.minio.MinioClient;
import io.minio.errors.*;
import lombok.extern.slf4j.Slf4j;

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * ClassName:MinioController
 * Package:com.example.blackjavaweb.controller
 * Description:操作minio对象数据库
 *
 * @Author QIQI_1999
 * @Creat 2023/10/14 20:42
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/minio")
public class MinioController {

    @Autowired
    private MinioClient minioClient;

    @Value("${minio.endpoint}")
    private String endpoint;

    @Autowired
    private MinioProperties minioProp;

    @Autowired
    private MinioService minioService;

    @PostMapping("/getfileurl")
    public Result getFileUrl(@RequestBody MinioPojo minioPojo) throws InvalidBucketNameException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, IOException, InvalidExpiresRangeException, InvalidKeyException, XmlParserException, InvalidResponseException, InternalException, InvalidPortException, InvalidEndpointException, ServerException {

//        System.out.println(minioClient);
//        System.out.println(endpoint);
        Object object = minioService.getFileName(minioPojo);
        return Result.success(object);

    }

}
